//? 只接受最高单位为亿
function numberToChinese(num) {
    const units = ['', '十', '百', '千', '万', '十万', '百万', '千万', '亿'];
    const digits = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
    let result = '';
    let numStr = num.toString();
    let numLen = numStr.length;
    for (let i = 0; i < numStr.length; i ++) {
        let digit = parseInt(numStr[i])
        let unit = units[numLen - i - 1]
        if (digit !== 0) {
            result += digits[digit] + unit

        }
        else {
            if (result[result.length - 1] !== '零') {
                result += digits[0]
            }

        }

    }
    //? 最后的结果应该只留最后一个万
    let resArr = Array.from(result)
    let lastOne = resArr.lastIndexOf('万')
    for (let i = 0 ; i < resArr.length; i ++) {
        if (i !== lastOne && resArr[i] === '万') {
            resArr[i] = '0'
        }
    }
    return resArr.join('').replaceAll("0","")
}
console.log(numberToChinese(1234)); // 一千二百三十四
console.log(numberToChinese(123456)); //
console.log(numberToChinese(1234567)); //
console.log(numberToChinese(10000001)); // 一千万零一
console.log(numberToChinese(100000001)); // 一亿零一
